//
//  Channel_playerIn_ViewController.m
//  STL_ Animation
//
//  Created by 孙健 on 16/4/6.
//  Copyright © 2016年 STL. All rights reserved.
//

#import "Channel_playerIn_ViewController.h"
#import "STL.h"
#import "MusicYue_V_Model.h"
#import "Channel_Playerin_Model.h"
#import "MusicYue_V_TableViewCell.h"
@interface Channel_playerIn_ViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, strong) UIImageView *imageViewHead;

@end

@implementation Channel_playerIn_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataSource = [NSMutableArray arrayWithCapacity:0];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"prev"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(backVc)];
    
    [self createTableView];
    [self createHeadView];
    [self getData];
}

- (void)backVc {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

- (void)getData {
    
    NSString *string = [NSString stringWithFormat:@"http://mapi.yinyuetai.com/artist/show.json?D-A=0&artistId=%@&size=20", self.artistId];
    [SJAFNetTool GEtNetWithUrl:string WithBody:nil headerFile:Dictionary response:SJJSON success:^(id result) {
       
        Channel_Playerin_Model *playerModel = [[Channel_Playerin_Model alloc] initWithDataSource:result[@"artist"]];
        
        [self.imageViewHead sd_setImageWithURL:[NSURL URLWithString:playerModel.smallAvatar]];
        
        NSArray *array = result[@"videos"];
        for (NSDictionary *dic in array) {
            
            MusicYue_V_Model *model = [[MusicYue_V_Model alloc] initWithDataSource:dic];
            [self.dataSource addObject:model];
        }
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {
        
    }];
}


- (void)createHeadView {
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.width/2)];
    headView.backgroundColor = [UIColor colorWithRed:99/255.0 green:99/255.0 blue:99/255.0 alpha:0.8];
    
    self.imageViewHead = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width/3, 10, self.view.bounds.size.width/3, self.view.bounds.size.width/3)];
    [self.imageViewHead.layer setCornerRadius:CGRectGetHeight([self.imageViewHead bounds])/2];
    self.imageViewHead.layer.masksToBounds = YES;
    
    UIImageView *imageViewStar = [[UIImageView alloc] initWithFrame:CGRectMake(headView.bounds.size.width/6 + 20, self.imageViewHead.bounds.size.height + 20,40, 40)];
    UIImageView *imageViewRight = [[UIImageView alloc] initWithFrame:CGRectMake(headView.bounds.size.width/6 * 4, self.imageViewHead.bounds.size.height + 20, 35, 35)];
    
    imageViewStar.image = [[UIImage imageNamed:@"xingxing"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    imageViewRight.image = [[UIImage imageNamed:@"xin"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    [headView addSubview:self.imageViewHead];
    [headView addSubview:imageViewStar];
    [headView addSubview:imageViewRight];
    self.tableView.tableHeaderView = headView;
}



#pragma mark - 创建tableview
- (void)createTableView {
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 64) style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    [self.tableView registerClass:[MusicYue_V_TableViewCell class] forCellReuseIdentifier:@"MusicYue_V_TableViewCell"];
    
    [self.view addSubview:self.tableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MusicYue_V_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MusicYue_V_TableViewCell"];
    cell.musicModel = self.dataSource[indexPath.item];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return self.view.bounds.size.width/4;
}


@end
